#pragma once

#include <Windows.h>
#include <string>

void log( std::string msg );	// some external log function, must be implemented somewhere

class CommPort
{
	int		port_number;
	int		baud_rate;
	COMMTIMEOUTS	original_timeouts;
	DCB		device_configuration;
	HANDLE	handle;
	OVERLAPPED	overlapped_read, overlapped_write;

public:
	///
	/// for handshake use 'EscapeCommFunction'
	///
	CommPort(int portnumber, int baudrate);

	bool _open();

	// Set terminal status line: Request To Send
	void setRTS(bool state);
	// Set terminal status line: Data Terminal Ready
	void setDTR(bool state);

	// Read terminal status line: Clear To Send
	bool getCTS();
	// Read terminal status line: Data Set Ready
	bool getDSR();
	// Read terminal status line: Ring Indicator
	bool getRI();
	// Read terminal status line: Carrier Detect
	bool getCD();

	void write( std::string & data );
	std::string read( int len=1 );

	void close();
};













